package spjm.pt.pmartins.racelogger;

import java.util.ArrayList;

//Contains Pilot's Data
public class Obj_Pilot {
	
	private String name;
	private int number;
	private ArrayList<Long> lapTimes;
	private boolean raceIsOver;
	
	Obj_Pilot(String name, int number){
		this.name = name;
		this.number = number;
		lapTimes = new ArrayList<Long>();
		raceIsOver = false;
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public int getNumber() {
		return number;
	}

	public void setNumber(int number) {
		this.number = number;
	}

	public ArrayList<Long> getLapTimes() {
		return lapTimes;
	}

	public void setLapTimes(ArrayList<Long> lapTimes) {
		this.lapTimes = lapTimes;
	}
	
	public int getNumberOfLaps(){
		return lapTimes.size();
	}
	
	public void resetLaps(){
		lapTimes.clear();
	}
	
	public void addLap(Long time){
		lapTimes.add( time - getTotalTime() );
	}
	
	public Long getTotalTime(){
		long totalTime = 0;
		for(Long time : lapTimes){
			totalTime += time;
		}
		return totalTime;
	}
	
	public Long getFastestTime(){
		if (lapTimes.isEmpty()){
			return (long) 0;
		}
		
		long fastestTime = Long.MAX_VALUE;
		for(Long time : lapTimes){
			if(time < fastestTime){
				fastestTime = time;
			}
		}
		return fastestTime;
	}
	
	public Long getAverageTime(){
		if (lapTimes.isEmpty()){
			return (long) 0;
		}
		
		return (getTotalTime() / lapTimes.size());
	}

	public boolean isRaceOver() {
		return raceIsOver;
	}

	public void setRaceIsOver(boolean raceIsOver) {
		this.raceIsOver = raceIsOver;
	}
	
	
	
}
